package js.dwim.domain;

import java.io.Serializable;

import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable( detachable = "true" )
@EmbeddedOnly
public class Point2D
        implements Serializable
{
    private static final long serialVersionUID = 1L;

    @PrimaryKey
    @Persistent( valueStrategy = IdGeneratorStrategy.IDENTITY )
    private Key key;

    @Persistent
    private double x;

    @Persistent
    private double y;

    public Point2D( double x, double y )
    {
        this.x = x;
        this.y = y;
    }

    public Key getKey()
    {
        return key;
    }

    public double distance( Point2D target )
    {
        double w = Math.abs( this.x - target.x );
        double h = Math.abs( this.y - target.y );

        return Math.sqrt( w * w + h * h );
    }

	public double getX() 
	{
		return x;
	}

	public void setX(double x) 
	{
		this.x = x;
	}

	public double getY() 
	{
		return y;
	}

	public void setY(double y) 
	{
		this.y = y;
	}
}
